{% extends "layout_base.html" %}
{% block title %}{% block admin_title %}{% endblock %}{% endblock %}
{% block base_head %}
	{% block admin_head %}
    {% endblock %}
{% endblock %}
{% block base_content %}
{% set perm = request.perm_const %}
<div id="body" class="admin">
  <div class="wrap">
    <h1 class="full"> 欢迎你，{{ request.user.nick_name }}
        <span class="extra">
            <a href="/" target="_blank" class="action">前台首页</a>
        </span>
    </h1>
    <div id="accordion" class="sidebar sortBox">
    	<h2 class="pointer">文件管理</h2>
		<ul class="element" id="file_manage_menu">
		  <li> <a href="/admin/file/upload/">上传文件</a> </li>
		</ul>
      {% if perm.check_perm_list([perm.perm_perm,perm.perm_op,perm.perm_role,perm.perm_user]) %}
        <h2 class="pointer">用户管理</h2>
        <ul class="element" id="user_manage_menu">
          {% if perm.check_perm(perm.perm_user) %}
          <li> <a href="/admin/user/normal/">用户列表</a> </li>
          {% endif %}
          {% if perm.check_perm(perm.perm_role) %}
          <li> <a href="/admin/user/auth/">管理员列表</a> </li>
          <li> <a href="/admin/role/">管理员角色表</a> </li>
          {% endif %}
          {% if perm.check_perm(perm.perm_perm) %}<li> <a href="/admin/perm/">权限列表</a> </li>{% endif %}
          {% if perm.check_perm(perm.perm_op) %}<li> <a href="/admin/op/">操作列表</a> </li>{% endif %}
        </ul>
      {% endif %}
    </div>
    <div class="adminContent">
    {% block admin_content %}{% endblock %}
    </div>
  </div>
</div>
<script type="text/javascript">
function setActive(url){
	var _container = $('accordion');
	var reg = new RegExp("/admin/.*\\?*"); 
	var href = url==null ? '' : url.toString();
	// 移除问号后所有内容
	var quindex = href.indexOf('?'); 
	if(quindex >= 0) href = href.substring(0,quindex);
	var all_lnks = _container.getElements('a');
	all_lnks.each(function(item,index){item.removeClass('active');});
	var elements = _container.getElements('ul.element');
	var show_ul_index = -1;
	for(var i=0;i<elements.length;i++){
		var alinks = elements[i].getElements('a');
		for(var j=0;j<alinks.length;j++){
			var aurl = reg.exec(alinks[j].href);
			var ahref = aurl==null ? '' : aurl.toString();
			if(href && ahref && href == ahref){
				alinks[j].addClass("active");
				show_ul_index = i;
				Cookie.write('last_active',url,{path:'/'});
				break;
			}		
		}
	}
	return show_ul_index;
}
window.addEvent('domready', function() {
	var reg = new RegExp("/admin/.*\\?*");
	var url = reg.exec(window.location.href);
	var index = setActive(url);
	if(index < 0) {
		url = Cookie.read('last_active');
		if(url) index = setActive(url);
	}
	var myAccordion = new Fx.Accordion($('accordion'),'h2.pointer', 'ul.element',{
		opacity: false, display:index
	});
});
</script>
{% endblock %}
